using System;
using Gj;
using Gj.Galaxy.Logic;
using Gj.Galaxy.Network;

namespace game.Galaxy
{
    public class BaseConnect
    {
        protected static Namespace n;
        protected static BaseConnect listener;
        protected static BasePage Page;

        public static Func<NamespaceListener> GetListener;

        protected Action<bool> OnConnectAction;

        public static void Init(Namespace ns)
        {
            n = ns;
            n.listener = GetListener();
        }

        public void OnConnect(bool success)
        {
            if (listener.OnConnectAction != null) listener.OnConnectAction(success);
        }


        public static void Connect(BasePage page, Action<bool> a)
        {
            Page = page;
            listener.OnConnectAction = a;
            if (n.Connect()) a(true);
        }

        public void OnError(string message)
        {
            if (ConnectManager.OnError != null) ConnectManager.OnError(message);
        }


        public object[] OnEvent(byte eb, object[] param)
        {
            return null;
        }

        public void OnReconnecting()
        {
        }

        public void OnReconnect(bool success)
        {
        }

        public void OnDisconnect()
        {
        }

        public static bool IsEmpty(object[] objs)
        {
            if (objs == null || objs.Length == 0 || objs[0] == null) return true;

            return false;
        }
    }
}